<?php
/**
 * group_chats
 *
 * @package group_chat
 *
 * @todo
 * - Either drop support for "publish date" or duplicate more entity getter
 * functions to work with a non-standard time_created.
 * - Pingbacks
 * - Notifications
 * - River entry for posts saved as drafts and later published
 */

elgg_register_event_handler('init', 'system', 'removedata_init');

/**
 * Init group_chat plugin.
 */
function removedata_init() {

	$projectlists = elgg_get_entities(array(
		'type' => "object",
		'subtype' => "projectlist",
	));
	foreach($projectlists as $projectlist){
		$projectlist->delete(true);
	}
	
	$projects = elgg_get_entities(array(
			'type' => "object",
			'subtype' => "project",
	));
	foreach($projects as $project){
		$project->delete(true);
	}
	
	
	$assignments = elgg_get_entities(array(
			'type' => "object",
			'subtype' => "assignment",
	));
	foreach($assignments as $assignment){
		$assignment->delete(true);
	}
	
// 	$groups = elgg_get_entities(array(
// 		'type' => "group"
// 	));
	
// 	foreach($groups as $group){
// 		$group->delete(true);
// 	}
}


function get_chat_content(){

	$guid = elgg_get_page_owner_guid();
	$days = elgg_get_plugin_setting('group_chat_days', 'group_chat');
	global $CONFIG;
	$fileContent = '';
    $days = ($days)?$days:2;
	for($i=$days;$i>=0;$i--){
	
		$filename = date('mdY', strtotime('-'.$i.' Days')).'.txt';
		$filepath = $CONFIG->dataroot.'/group_chat/'.$guid.'/'.$filename;		
		$content = file_get_contents($filepath);
		if($content)
		$fileContent .= '<li class="dateD" >'.date('D, F d, Y', strtotime('-'.$i.' Days')).'<li>';
	
		$fileContent .= $content;
		
	}
	
	return $fileContent;
	
}
?>
